package com.cta.service.jms.consumer;

import javax.jms.JMSException;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.listener.SessionAwareMessageListener;

import com.cta.jms.MessageProducer;

public class ConsumerService implements
		SessionAwareMessageListener<TextMessage> {
	private static final Logger LOG = LoggerFactory
			.getLogger(ConsumerService.class);

	@Autowired
	private MessageProducer producer;
	
	public void onMessage(TextMessage message, Session session)
			throws JMSException {
		try {
			TextMessage msg = message;
			LOG.info("Consumed message: " + msg.getText());
			producer.sendMessages("Process and Send " + msg.getText());
		} catch (JMSException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
